import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
from  ReadReview import Read
from datetime import *


def getDateFromTime(time):
     year = int(time['year'])
     month = int(time['month'])
     day = int(time['day'])
     D = date(year, month, day)
     return D.weekday()  # return 0 if monday;  1 if tuesday and so on


# Example data
if __name__ == '__main__':
   days = ('Mon', 'Tues',  'Wedn','Thurs','Fri','Sat','Sun')
   y_pos = np.arange(len(days))
   numbers=[0,0,0,0,0,0,0]
   info = Read()
   list = []
   list = info.get_infolist()
   print('complete reading file,start to analyse')
   for i in range(0, len(list)):
        weekday = getDateFromTime(list[i]['time'])
        numbers[weekday]=numbers[weekday]+1
            
       
   print(numbers)
   error = np.random.rand(len(days))
   plt.barh(y_pos, numbers, xerr=error, align='center', alpha=0.4)
   plt.yticks(y_pos, days)
   plt.xlabel('Numbers')
   plt.title('Number of Reviews in each Weekday')
# plt.subplot(320+i)
   plt.show()
      
 